package com.atguigu.day03;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

public class Flink08_Transform_Union {
    public static void main(String[] args) throws Exception {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2.分别创建两条流
        DataStreamSource<Integer> integerDataStreamSource1 = env.fromElements(1, 2, 3, 4, 5, 6);
        DataStreamSource<Integer> integerDataStreamSource2 = env.fromElements(7,8,9,10);
        DataStreamSource<Integer> integerDataStreamSource3 = env.fromElements(100,200,300);


        //TODO 3.使用union连接多条流
        DataStream<Integer> union = integerDataStreamSource1.union(integerDataStreamSource2, integerDataStreamSource3);

        union.map(new MapFunction<Integer, String>() {
            @Override
            public String map(Integer value) throws Exception {
                return value + "@";
            }
        }).print();


        env.execute();
    }
}
